<?php
session_start();

include_once 'recursos/funciones.php';
include_once 'recursos/config.php';

$config = new configuracion();

$usuario_session = $_SESSION["g2uSystemName"];

$usuario = trim($_REQUEST["user_name"]);
$usuario = strip_tags($usuario);

if (strlen($usuario)<6){
    ?>
    <script>
        alert("No existe");
        document.location.href = '<?=$config->getG2uDominio()?>';
    </script>
    <?
    exit();
}

$id = validar_usuario_existe($usuario);
if ($id){
    
    if(validar_friendship($_SESSION["g2uId"] , $id) || $_SESSION["g2uId"] == $id){
        cargarSesionAmigo($id);
        $_SESSION["dataWishList"] = cargar_wishlist($id);

        $_SESSION["dataUser"]["g2uId"] = $id;
        $_SESSION["dataUser"]["g2uProfilePic"] = $_SESSION["g2uFriendProfilePic"];
        $_SESSION["dataUser"]["g2uFirstName"] = $_SESSION["g2uFriendFirstName"];
        $_SESSION["dataUser"]["g2uLastName"] = $_SESSION["g2uFriendLastName"];
        
        /*$_SESSION["g2uFriendId"] = $fila["user_id"];
        $_SESSION["g2uFriendSystemName"] = $fila["user_sys_name"];
        $_SESSION["g2uFriendName"] = $fila["user_name"];
        $_SESSION["g2uFriendMail"] = $fila["user_mail"];
        $_SESSION["g2uFriendBirthday"] = $date->convertirFechatoNormal($fila["user_birthday"]);
        $_SESSION["g2uFriendFirstName"] = $fila["user_fname"];
        $_SESSION["g2uFriendLastName"] = $fila["user_lname"];
        $_SESSION["g2uFriendProfilePic"] = $fila["user_profile_pic"];
        $_SESSION["g2uFriendRegDate"] = $fila["user_register_date"];*/
        
        include_once 'perfil_amigo.php';
    } else {
        include_once 'principal.php';
        //include_once 'vista/vista.perfil.no.friend.php';
    }
    
} else {
    ?>
    <script>
        alert("Busqueda Incorrecta");
        // Implementar Seccion busquedas
        document.location.href = '<?=$config->getG2uDominio()?>';
    </script>
    <?
}
?>
